package leetcodecompetition.D379;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: Siantar
 * @Date: 2024-01-07-11:12
 * @Description: 1.0
 */
public class T100150 {
    public int maximumSetSize(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int num : nums1) {
            set1.add(num);
        }
        int p = set1.size();
        for (int num : nums2) {
            set1.add(num);
            set2.add(num);
        }
        int q = set2.size();
        int s = set1.size();
        int t = p + q - s;
        p -= t;
        q -= t;
        int n = nums1.length / 2;
        int res = 0;
        res += Math.min(n, p + t);
        t = Math.max(0, t - Math.max(0, n - p));
        res += Math.min(n, q + t);
        return res;
    }
}
